<template>
  <div class="page">
    <!-- 头部 -->
    <header class="header">
      <p class="pp">舌象识别</p>
      <div class="tom">
        <img
          src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-5405fd0b85bd96319399d4e5c63ebf42_hd.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1621084218&t=96bc6a306ad97e07a21b2d745b3f2f1b"
          alt
        />
        <div class="text">
          <p class="p1">灸友39087</p>
          <p class="p2">2020-03-12 12:30</p>
        </div>
      </div>
    </header>
    <div class="content">
      <div class="tab">
        <span @click="active = 1" :class="{ active: active == 1 }"
          >识别结果</span
        >
        <span @click="active = 2" :class="{ active: active == 2 }"
          >调理方案</span
        >
      </div>
      <!-- // 识别结果 -->
      <ul v-if="active == 1">
        <div>{{ resp.search_data.main_visceral }}</div>
        <li>
          <p>{{ resp.search_data.main_visceral_language }}</p>
        </li>
        <div class="other">
          <span>舌质</span>
          <img :src="url" alt="" />
        </div>
        <li>
          <p>{{ resp.search_data.tongue_quality_language }}</p>
        </li>
        <div>舌苔</div>
        <li>
          <p>{{ resp.search_data.tongue_coating_language }}</p>
        </li>
      </ul>
      <!-- // 调理方案页面 -->
      <div v-else-if="active == 2" class="idea">
        <div
          v-for="(item, attr) in conditioning_data"
          :key="attr"
          class="idea_bod"
        >
          <div class="idea_tite">
            <img :src="item.url" />
            <span>{{ item.broadHeading }}</span>
          </div>
          <div
            v-for="(item1, attr) in item.schemes"
            :key="attr"
            class="idea_min"
          >
            <span @click="get_nameCare_detail(item1)">{{ item1 }}</span>
          </div>
        </div>
      </div>
      <!-- 底部 -->
      <p class="tips">舌象报告仅供参考，不能作为医学依据</p>
      <a @click="handleGo" class="btn">下一步</a>
    </div>
    <!-- 方案详情弹框 -->
    <van-popup
      v-model="show"
      closeable
      position="bottom"
      :style="{ height: '30%' }"
    >
      <div v-html="shows"></div>
    </van-popup>
  </div>
</template>
<script>
import { nameCare, nameCare_detail } from "../../utils/api";
import { Toast } from "vant";
export default {
  name: "discernResult",
  data() {
    return {
      active: 1,
      show: false,
      shows: "",
      resp: {},
      url: JSON.parse(window.localStorage.getItem("files")),
      conditioning_data_img: [
        { url: require("../../assets/aa.jpg") },
        { url: require("../../assets/bb.jpg") },
        { url: require("../../assets/cc.jpg") },
      ],
      conditioning_data: [],
    };
  },
  created() {
    //console.log(this.url, "localstore");
    const resp = JSON.parse(this.$route.query.resp);
    this.resp = resp.data;
    console.log(this.resp,'将tongue路由传过来的上传图片后的返回数据保存到当前组件data')

    this.get_nameCare_detail();
    this.get_nameCare();
  },
  methods: {
    async get_nameCare() {
      let res = await nameCare({
        visceral: this.resp.search_data.vice_visceral,
      });
      console.log(res, '对应副脏象名调理方案的返回数据');
      this.conditioning_data =
        res.data.data &&
        res.data.data.map((item, index) => ({
          ...item,
          ...this.conditioning_data_img[index],
        }));
    },
    async get_nameCare_detail(item) {
      try {
        const params = { name: item };
        const res = await nameCare_detail(params);
        console.log(res,'调理方案详情返回数据');
        const { data } = res;
        const { msg } = data;
        if (msg == "succeed") {
          this.show = true;
          let resp = data.data.detail.replace(/【/g, "<br>【");
          this.shows = resp;
        } else {
          Toast(msg + "---啥意思");
        }
      } catch (err) {
        console.log(err);
      }
    },
    handleGo() {
      const resp = this.$route.query.resp;
      const query = {
        resp,
      };
      this.$router.push({
        path: "/selectCharacteristic",
        query,
      });
    },
  },
  mounted() {},
};
</script>
<style lang="less" scoped>
.page {
  background: rgb(250, 252, 251);
}
.header {
  background: rgb(3, 223, 197);
  color: #fff;
  padding: 0.4rem 0 1.8rem 0.4rem;
  .text {
    .p1 {
      padding: 0;
      margin-bottom: 10px;
    }
    p {
      text-align: left;
    }
  }
  .pp {
    padding: 15px 0;
    text-align: center;
    font-size: 18px;
  }
  .tom {
    display: flex;
    align-items: center;
  }
  img {
    width: 2rem;
    height: 2rem;
    border-radius: 2rem;
    border: 0.1rem solid rgb(3, 223, 197);
    margin-right: 0.3rem;
  }
  .p1 {
    padding-bottom: 0.4rem;
  }
}
.content {
  position: relative;
  top: -1rem;
  width: 9rem;
  margin: 0 auto;
  .tab {
    color: #606060;
    font-weight: bold;
    width: 100%;
    position: relative;
    span {
      width: 4.5rem;
      text-align: center;
      line-height: 1.4rem;
      height: 1.2rem;
      display: block;
      position: absolute;
      top: 0;
      background: rgb(242, 242, 242);
      &:first-child {
        left: 0;
        border-radius: 0.2rem 0 0 0;
        &.active {
          background: #fff;
          height: 1.8rem;
          top: -0.4rem;
          width: 4.54rem;
          line-height: 2.1rem;
          border-radius: 0;
          border-radius: 0.2rem 0.6rem 0 0;
          color: rgb(3, 223, 197);
        }
      }
      &:last-child {
        right: 0;
        border-radius: 0 0.2rem 0 0;
        &.active {
          background: #fff;
          height: 1.8rem;
          top: -0.4rem;
          width: 4.54rem;
          line-height: 2.1rem;
          border-radius: 0;
          border-radius: 0.6rem 0.2rem 0 0;
          color: rgb(3, 223, 197);
        }
      }
    }
  }
  .idea {
    padding-top: 2rem;
    .idea_bod {
      margin-bottom: 20px;
    }
    .idea_tite {
      display: flex;
      align-items: center;
      img {
        height: 30px;
        width: 30px;
        margin-right: 5px;
      }
    }
    .idea_min {
      padding: 8px;
      display: inline-block;
      margin-top: 5px;
      span {
        color: green;
        background-color: #f2f2f2;
        padding: 10px;
      }
    }
  }
  ul {
    padding-top: 2rem;
    .other {
      display: flex;
      align-items: center;

      img {
        width: 1rem;
        border-radius: 50%;
        height: 1rem;
        margin-left: 0.1rem;
      }
    }
    li {
      font-size: 0.4rem;
      margin-bottom: 0.4rem;
      border-bottom: 0.1rem solid #ececec;
      padding: 0.3rem;
      background: #fff;

      p {
        font-size: 0.28rem;
        color: #666;
      }
    }
  }
  .tips {
    text-align: center;
    color: red;
    padding-top: 1rem;
    padding-bottom: 0.2rem;
    font-size: 0.28rem;
  }
  .btn {
    width: 100%;
    height: 1rem;
    background: rgb(2, 207, 128);
    color: #fff;
    display: block;
    text-align: center;
    line-height: 1rem;
    border-radius: 1rem;
  }
}
</style>
